package com.macaline.util;

import com.macaline.bean.LoginUser;
import com.macaline.entity.User;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;

public class LoginUtil {
    /**
     * 获取登录的用户所有信息
     * @return
     */
    public static LoginUser getLoginUser(){
        Subject subject = SecurityUtils.getSubject();
        LoginUser loginUser = (LoginUser) subject.getPrincipal();
        return loginUser;
    }

    /**
     * 获取登录用户的基本信息
     * @return
     */
    public static User getUser(){
        LoginUser loginUser = getLoginUser();
        if(loginUser != null) {
            return loginUser.getUser();
        }else {
            return null;
        }
    }


    /**
     * 设置登录用户的基本信息
     * @param user
     */
    public void setUser(User user) {
        LoginUser loginUser = getLoginUser();
        if(loginUser != null){
            loginUser.setUser(user);
        }
    }
}
